<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>选择一个词干提取器 | Elasticsearch: 权威指南 | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch: 权威指南">
<link rel="up" href="stemming.html" title="将单词还原为词根">
<link rel="prev" href="hunspell.html" title="Hunspell 词干提取器">
<link rel="next" href="controlling-stemming.html" title="控制词干提取">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Definitive Guide">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="2.x">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="zh_cn">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="languages.html">处理人类语言</a></span>
»
<span class="breadcrumb-link"><a href="stemming.html">将单词还原为词根</a></span>
»
<span class="breadcrumb-node">选择一个词干提取器</span>
</div>
<div class="navheader">
<span class="prev">
<a href="hunspell.html">« Hunspell 词干提取器</a>
</span>
<span class="next">
<a href="controlling-stemming.html">控制词干提取 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="choosing-a-stemmer"></a>选择一个词干提取器<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/230_Stemming/40_Choosing_a_stemmer.asciidoc">edit</a>
</h2>
</div></div></div>
<p>在文档
<a href="/guide/en/elasticsearch/reference/5.6/analysis-stemmer-tokenfilter.html" class="ulink" target="_top"><code class="literal">stemmer</code></a> token filter
里面列出了一些针对语言的若干词干提取器。
就英语来说我们有如下提取器：</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">english</code>
</span>
</dt>
<dd>
<a href="/guide/en/elasticsearch/reference/5.6/analysis-porterstem-tokenfilter.html" class="ulink" target="_top"><code class="literal">porter_stem</code></a>​ 语汇单元过滤器（token filter）。
</dd>
<dt>
<span class="term">
<code class="literal">light_english</code>
</span>
</dt>
<dd>
<a href="/guide/en/elasticsearch/reference/5.6/analysis-kstem-tokenfilter.html" class="ulink" target="_top"><code class="literal">kstem</code></a> 语汇单元过滤器（token filter）。
</dd>
<dt>
<span class="term">
<code class="literal">minimal_english</code>
</span>
</dt>
<dd>
Lucene 里面的 <code class="literal">EnglishMinimalStemmer</code> ，用来移除复数。
</dd>
<dt>
<span class="term">
<code class="literal">lovins</code>
</span>
</dt>
<dd>
基于 <a href="/guide/en/elasticsearch/reference/5.6/analysis-snowball-tokenfilter.html" class="ulink" target="_top">Snowball</a> 的
<a href="http://snowball.tartarus.org/algorithms/lovins/stemmer.html" class="ulink" target="_top">Lovins</a>
提取器, 第一个词干提取器。
</dd>
<dt>
<span class="term">
<code class="literal">porter</code>
</span>
</dt>
<dd>
基于 <a href="/guide/en/elasticsearch/reference/5.6/analysis-snowball-tokenfilter.html" class="ulink" target="_top">Snowball</a> 的
<a href="http://snowball.tartarus.org/algorithms/porter/stemmer.html" class="ulink" target="_top">Porter</a> 提取器。
</dd>
<dt>
<span class="term">
<code class="literal">porter2</code>
</span>
</dt>
<dd>
基于 <a href="/guide/en/elasticsearch/reference/5.6/analysis-snowball-tokenfilter.html" class="ulink" target="_top">Snowball</a> 的
<a href="http://snowball.tartarus.org/algorithms/english/stemmer.html" class="ulink" target="_top">Porter2</a> 提取器。
</dd>
<dt>
<span class="term">
<code class="literal">possessive_english</code>
</span>
</dt>
<dd>
Lucene 里面的 <code class="literal">EnglishPossessiveFilter</code> ，移除 <code class="literal">'s</code>
</dd>
</dl>
</div>
<p>Hunspell 词干提取器也要纳入到上面的列表中，还有多种英文的词典可用。</p>
<p>有一点是可以肯定的：当一个问题存在多个解决方案的时候，这意味着没有一个解决方案充分解决这个问题。
这一点同样体现在词干提取上 — 每个提取器使用不同的方法不同程度的对单词进行了弱提取或是过度提取。</p>
<p>在 <code class="literal">stemmer</code> 文档 中，使用粗体高亮了每一个语言的推荐的词干提取器，
通常是因为它提供了一个在性能和质量之间合理的妥协。也就是说，推荐的词干提取器也许不适用所有场景。
关于哪个是最好的词干提取器，不存在一个唯一的正确答案 — 它要看你具体的需求。
这里有3个方面的因素需要考虑在内：
性能、质量、程度。</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="stemmer-performance"></a>提取性能<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/230_Stemming/40_Choosing_a_stemmer.asciidoc">edit</a>
</h3>
</div></div></div>
<p>算法提取器一般来说比 Hunspell 提取器快4到5倍。
“Handcrafted” 算法提取器通常（不是永远） 要比 Snowball 快或是差不多。
比如，<code class="literal">porter_stem</code> 语汇单元过滤器（token filter）就明显要比基于 Snowball 实现的 Porter 提取器要快的多。</p>
<p>Hunspell 提取器需要加载所有的词典、前缀和后缀表到内存，可能需要消耗几兆的内存。而算法提取器，由一点点代码组成，只需要使用很少内存。</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="stemmer-quality"></a>提取质量<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/230_Stemming/40_Choosing_a_stemmer.asciidoc">edit</a>
</h3>
</div></div></div>
<p>所有的语言，除了世界语（Esperanto）都是不规范的。
最日常用语使用的词往往不规则，而更正式的书面用语则往往遵循规律。
一些提取算法经过多年的开发和研究已经能够产生合理的高质量的结果了，其他人只需快速组装做很少的研究就能解决大部分的问题了。</p>
<p>虽然 Hunspell 提供了精确地处理不规则词语的承诺，但在实践中往往不足。
一个基于词典的提取器往往取决于词典的好坏。如果 Hunspell 碰到的这个词不在词典里，那它什么也不能做。
Hunspell 需要一个广泛的、高质量的、最新的词典以产生好的结果；这样级别的词典可谓少之又少。
另一方面，一个算法提取器，将愉快的处理新词而不用为新词重新设计算法。</p>
<p>如果一个好的算法词干提取器可用于你的语言，那明智的使用它而不是 Hunspell。它会更快并且消耗更少内存，并且会产生和通常一样好或者比 Hunspell 等价的结果.</p>
<p>如果精度和可定制性对你很重要，那么你需要（和有精力）来维护一个自定义的词典，那么 Hunspell 会给你比算法提取器更大的灵活性。 (查看
<a class="xref" href="controlling-stemming.html" title="控制词干提取">控制词干提取</a> 来了解可用于任何词干提取器的自定义技术。)</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="stemmer-degree"></a>提取程度<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/230_Stemming/40_Choosing_a_stemmer.asciidoc">edit</a>
</h3>
</div></div></div>
<p>不同的词干提取器会将词弱提取或过度提取到一定的程度。  <code class="literal">light_</code>
提取器提干力度不及标准的提取器。 <code class="literal">minimal_</code> 提取器同样也不那么积极。Hunspell 提取力度要激进一些。</p>
<p>是否想要积极提取还是轻量提取取决于你的场景。如果你的搜索结果是要用于聚类算法，你可能会希望匹配的更广泛一点（因此，提取力度要更大一点）。
如果你的搜索结果是面向最终用户，轻量的提取一般会产生更好的结果。对搜索来说，将名称和形容词提干比动词提干更重要，当然这也取决于语言。</p>
<p>另外一个要考虑的因素就是你的文档集的大小。
一个只有 10,000 个产品的小集合，你可能要更激进的提干来确保至少匹配到一些文档。
如果你的文档集很大，使用轻量的弱提取可能会得到更好的匹配结果。</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_做一个选择"></a>做一个选择<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/230_Stemming/40_Choosing_a_stemmer.asciidoc">edit</a>
</h3>
</div></div></div>
<p>从推荐的一个词干提取器出发，如果它工作的很好，那没有什么需要调整的。如果不是，你将需要花点时间来调查和比较该语言可用的各种不同提取器，
来找到最适合你目的的那一个。</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="hunspell.html">« Hunspell 词干提取器</a>
</span>
<span class="next">
<a href="controlling-stemming.html">控制词干提取 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
